#include <tchar.h>
#include "Game.h"
#include "Text.h"

#define _TEXTHELP(x)      L ## x

HRESULT Text::Load()
{
	D3DXFONT_DESC fontDesc;
	fontDesc.Height = 100;
	fontDesc.Width = 100;
	fontDesc.Weight = FW_BOLD;
	fontDesc.MipLevels = 0;
	fontDesc.Italic = FALSE;
	fontDesc.CharSet = DEFAULT_CHARSET;
	fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
	fontDesc.Quality = DEFAULT_QUALITY;
	fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	wcscpy_s(fontDesc.FaceName, _T("Arial"));
	
	if(FAILED(D3DXCreateFontIndirect(TheGame::Instance()->m_pd3dDevice, &fontDesc, &m_font)))
	{
		return E_FAIL;
	}
	return S_OK;
}

HRESULT Text::Update()
{
	return S_OK;
}

void Text::SetText(const std::string& text)
{
	m_text = text;
}

void Text::Draw()
{
	RECT formatRect;
	GetClientRect(TheGame::Instance()->GetWindowHandle(), &formatRect);
	std::wstring string(m_text.begin(), m_text.end());
	const wchar_t* wtext = string.c_str();
	m_font->DrawText(0, wtext, -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(255, 255, 255));
}

void Text::Unload()
{
	m_font->Release();
}